<template>
    <div class="content">
        <div class="header">
            <el-input v-model="text"></el-input>
            <el-button type="primary" @click="uploadipfs">
                上传星际系统
            </el-button>
        </div>
        <div class="desc">
            您上传内容的星际系统密钥为:{{this.hash}}
        </div>
    </div>
</template>

<script>
import ipfsAPI from "ipfs-api";
let ipfs = ipfsAPI("localhost", "5002", { protocol: "http" });
export default {
    data () {
        return {
            text: '',
            hash: ''
        }
    },
    methods: {
        uploadipfs () {
            const descBuf = Buffer.from(this.text, "utf-8");
            ipfs.add(descBuf).then((res) => {
                this.hash = res[0].hash;
                this.$message.success("上传星际系统成功");
            });
        }
    }
}
</script>

<style lang="less" scoped>
.content {
    width: 70%;
    margin: 0 auto;
    .header {
        display: flex;
    }
    .desc {
        margin-top: 10px;
    }
}
</style>